<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>订单结算</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">

</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">订单结算</div>
                <div class="layui-card-body"> 
                       <div class="layui-form-item layui-form"> 
                        <div class="layui-inline" >
                            <label class="layui-form-label" >订单编号</label>
                               <div class="layui-input-block">
                                <input type="text" name="order_sn" id="order_sn_"   placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-btn-group test-table-operate-btn">
                                <button class="layui-btn" data-type="searchUserButton">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div> 

                    </div>
                    <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate">

                    </table>

                    <script type="text/html" id="test-table-operate-barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>  

<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
        var $ = layui.$, active = {
            addadmin: function() {
                window.location.href="{:url('Settlements/settledquery')}";
            },
            searchUserButton:function(){ 
                var order_sn     = $('#order_sn_').val(); 
                table.reload('test-table-operate', {
                    where: {
                        order_sn:order_sn
                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            }
        };

    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'table', 'laydate', 'set'], function () {
        $ = layui.jquery;
        var table = layui.table
            , admin = layui.admin
            , element = layui.element
            , layer = layui.layer
            , laydate = layui.laydate
            , form = layui.form;

        table.render({
            elem: '#test-table-operate'
            , url: "{:url('Settlements/settledquery')}"
            , height: 'full-155'
            , cols: [[
                {field: 'order_sn', align: 'center', width: 200, title: '结算订单号'}
                , {field: 'pay_type', align: 'center', width: 200, title: '支付方式'}
                , {field: 'total_price', align: 'center', title: '酒店价格'}
                , {field: 'order_price', align: 'center', title: '实付金额'} 
                , {field: 'commission_fee', align: 'center', title: '应付佣金'} 
                , {field: 'settlement_no', align: 'center', title: '结算单号'}
                , {field: 'settlement_time', align: 'center', title: '结算时间'}
            ]]
        });

        form.render(null, 'component-form-group');

        laydate.render({
            elem: '#LAY-component-form-group-date'
        });


        //监听工具条
        table.on('tool(test-table-operate)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确认删除房间"' + data.room_number + '"吗', function (index) {
                    
                    if (data.is_ruzhu == 1){
                        layer.msg('房间处于入住状态，不可删除', {icon: 2, time: 1000});
                        return false;
                    }
                    
                    var loading = layer.load(1, {
                        shade: [0.1, '#fff'] //0.1透明度的白色背景
                    });

                    $.ajax({
                        url: "{:url('Room/delRoom')}",
                        type: 'post',
                        dataType: 'json',
                        data: {eroom_id: data.eroom_id},
                        success: function (msg) {
                            layer.close(loading);
                            if (msg.code === 0) {
                                obj.del();
                                layer.close(index);
                            } else if (msg.code === 1) {
                                layer.msg('删除失败', {icon: 2, time: 1000});
                            }
                        }
                    })

                });
            } else if (obj.event === 'edit') {                           //修改操作],

                $('#edit_eroom_id').val(data.eroom_id);
                $('#edit_room_id').val(data.room_id);
                $('#edit_room_number').val(data.room_number);
                $('#edit_remarks').val(data.remarks);
                
                form.render();


                layer.open({
                    title: '修改房间信息'
                    , type: 1
                    , shadeClose: true
                    , area: ['1200px']
                    , content: $('#editmodal')
                });

            }
        });

        //添加提交
        form.on('submit(addsubmit)', function (data) {

            var loading = layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });

            $.ajax({
                url: "{:url('Room/addRoom')}",
                type: 'post',
                dataType: 'json',
                data: {data: data.field},
                success: function (data) {
                    layer.close(loading);
                    if (data.code === 0) {
                        layer.msg('添加成功', {icon: 1, time: 2000}, function () {
                            window.location.reload();
                        });
                    } else {
                        layer.msg('添加失败', {icon: 2, time: 1000});
                    }
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        //修改提交
        form.on('submit(editsubmit)', function (data) {
            var loading = layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            $.ajax({
                url: "{:url('Room/editRoom')}",
                type: 'post',
                dataType: 'json',
                data: {data: data.field},
                success: function (info) {
                    if (info.code === 0) {
                        layer.msg('修改成功', {icon: 1, time: 2000}, function () {
                            window.location.reload();
                        });
                    } else {
                        layer.close(loading);
                        layer.msg(info.code, {icon: 2, time: 1000})
                    }
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });


        var $ = layui.$, active = {
            addadmin: function () {
                var addmodal = layer.open({
                    title: '添加房间'
                    , type: 1
                    , shadeClose: true
                    , area: ['600px']
                    , content: $('#addmodal')
                });
            }

        };

        $('.test-table-operate-btn .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });


    //格式化时间函数
    function Format(datetime, fmt) {
        if (parseInt(datetime) == datetime) {
            if (datetime.length == 10) {
                datetime = parseInt(datetime) * 1000;
            } else if (datetime.length == 13) {
                datetime = parseInt(datetime);
            }
        }
        datetime = new Date(datetime);
        var o = {
            "M+": datetime.getMonth() + 1,                 //月份
            "d+": datetime.getDate(),                    //日
            "h+": datetime.getHours(),                   //小时
            "m+": datetime.getMinutes(),                 //分
            "s+": datetime.getSeconds(),                 //秒
            "q+": Math.floor((datetime.getMonth() + 3) / 3), //季度
            "S": datetime.getMilliseconds()             //毫秒
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (datetime.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }

</script>


</body>
</html>